#include <pthread.h>
#include <thread>
#include <mutex>
#include <condition_variable>
#include <iostream>
using namespace std;
int main()
{
    // c++的线程库只有一个参数
    int n = 100;
    mutex m1, m2;
    condition_variable c1;
    bool flag = false;
    thread t1([&]()
              {for(int i = 0;i<=n;i+=2){
                unique_lock<mutex> ug(m1);
                if(flag){
                    c1.wait(ug);
                }
        cout<<"t1:"<< i<<endl;
        flag = true;
        c1.notify_one();
    } });

    thread t2([&]()
              {for(int i = 1;i<=n;i+=2){
                unique_lock<mutex> ug2(m2);
                if(!flag){
                    c1.wait(ug2);
                }
        cout<<"t2:"<<i<<endl;
        flag = false;
        c1.notify_one();
    } });

    t1.join();
    t2.join();

    return 0;
}